import request from "@/utils/request";
import {serviceModulePrefix, useDecorateApi} from "@/utils/tools";

// 查询课程体系列表
export const apiArchList = (params, opts) => useDecorateApi(request({
  url: `${serviceModulePrefix}/archInfo/list`,
  params
}), {
  toast: false,
  ...opts
})

// 复制课程体系
export const apiArchClone = (id, opts) => useDecorateApi(request({
  url: `${serviceModulePrefix}/archInfo/clone/${id}`
}), opts)


// 删除课程体系
export const apiArchDel = (id, opts) => useDecorateApi(request({
  url: `${serviceModulePrefix}/archInfo/${id}`,
  method: 'delete'
}), opts)


// 新建课程体系
export const apiArchAdd = (formData, opts) => useDecorateApi(request({
  url: `${serviceModulePrefix}/archInfo/add`,
  method: 'post',
  data: {...unref(formData)}
}), opts)


// 修改该课程体系
export const apiArchPut = (formData, opts) => useDecorateApi(request({
  url: `${serviceModulePrefix}/archInfo/revise`,
  method: 'put',
  data: {...unref(formData)}
}), opts)


// 修改课程体系大纲
export const apiArchSet = (formData, ctxData, opts) => useDecorateApi(request({
  url: `${serviceModulePrefix}/archStageInfo/revise`,
  method: 'post',
  data: [...formData],
  transformRequest: (data) => {
    const {id: archId} = unref(ctxData)
    data = data.map(({stageName = '', archStageCourseInfoVos = [], id}, sort1) => ({
      id,
      stageName,
      archId,
      sort: sort1,
      archStageCourseInfoDtos: archStageCourseInfoVos.map(({id, courseName = '', courseSession, stageId}, sort2) => ({
        id,
        courseName,
        courseSession,
        archId,
        stageId,
        sort: sort2
      }))
    }))
    return JSON.stringify(data);
  },
}), opts)


// 查询课程体系大纲详情
export const apiArchDetail = (id, opts) => useDecorateApi(request({
  url: `${serviceModulePrefix}/archInfo/${id}`
}), {
  dataCleaning: res => res.data,
  ...opts
})
